package com.hntest.service.impl;

import com.hntest.dao.BidDao;
import com.hntest.entity.Bid;
import com.hntest.entity.Pager;
import com.hntest.service.BidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("BidService")
public class BidServiceImpl implements BidService {

    @Autowired
    private BidDao bidDao;
    public void setBidDao(BidDao bidDao) {
        this.bidDao = bidDao;
    }

    @Override
    public int getCounts(Bid bid) {
        return bidDao.getCounts(bid);
    }

    @Override
    public List<Bid> getListByPage(Pager pager,Bid bid) {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("Bid",bid);
        map.put("pageStart",1);
        map.put("pageEnd",10000);
        int n = bidDao.getListByPage(map).size();
        pager.setTotalCounts(n);
        map.put("pageStart",(pager.getCurrPage()-1)*pager.getPageSize()+1);
        map.put("pageEnd",pager.getCurrPage()*pager.getPageSize());
        System.out.println("------------------->"+(pager.getCurrPage()-1)*pager.getPageSize()+1);
        System.out.println("------------------->"+pager.getCurrPage()*pager.getPageSize());
        List<Bid> list= bidDao.getListByPage(map);
        //System.out.println("......>"+list.get(0));
        return list;
    }

    @Override
    public int insert(Bid bid) {
        int n = 0;
        try{
            System.out.println("正在新增投资数据");
            n = bidDao.insert(bid);
        }catch (Exception e){
            e.printStackTrace();
        }
        if (n!=0) System.out.println("成功新增投资数据！");
        return n;
    }

    //更新债主 list  看情况做不做
    @Override
    public int update(Bid bid) {
        return 0;
    }

}
